from django.db import models

class FoodsChannelGroup(models.Model):
    """三餐频道组"""
    name = models.CharField(max_length=20, verbose_name='频道组名')

    class Meta:
        db_table = 'tb_foods_channel_group'
        verbose_name = '三餐频道组'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class FoodsCategory(models.Model):
    """三餐对应种类"""
    name = models.CharField(max_length=10, verbose_name='食物分类名称')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
    group = models.ForeignKey(FoodsChannelGroup, verbose_name='频道组名')

    class Meta:
        db_table = 'tb_foods_category'
        verbose_name = '三餐对应种类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class FoodsChannel(models.Model):
    """三餐对应频道"""
    name = models.CharField(max_length=50,verbose_name='食物名称')
    introduce = models.CharField(max_length=100,verbose_name='食物介绍')
    price = models.IntegerField(max_length=20,verbose_name='食物价格')
    url = models.CharField(max_length=500, verbose_name='食物页面链接')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
    category = models.ForeignKey(FoodsCategory, on_delete=models.CASCADE, verbose_name='顶级商品类别')
    comments = models.IntegerField(default=0, verbose_name='评价数')
    discount = models.IntegerField(null=True, verbose_name='具体折扣')

    class Meta:
        db_table = 'tb_foods_channel'
        verbose_name = '三餐对应频道'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.category.name



